Skip to content

fix(mcp): route web_search to Amazon Q endpoint with profile ARN for AWS SSO OIDC accounts - #237

Open
yeeyon wants to merge 1 commit into
jwadow:mainfrom
yeeyon:fix/mcp-websearch-sso-profilearn
Open

fix(mcp): route web_search to Amazon Q endpoint with profile ARN for AWS SSO OIDC accounts#237
yeeyon wants to merge 1 commit into
jwadow:mainfrom
yeeyon:fix/mcp-websearch-sso-profilearn

Conversation

@yeeyon

@yeeyon yeeyon commented Jun 29, 2026

Copy link
Copy Markdown

Problem

web_search (via the Kiro MCP endpoint) fails for kiro-cli / AWS SSO OIDC accounts.

call_kiro_mcp_api sends the request to https://runtime.{region}.kiro.dev/mcp (the q_host) without a profile ARN. For AWS SSO OIDC accounts that endpoint rejects the call:

  1. 400 Bad Request - profileArn is required
  2. after adding the ARN to the body, 403 Forbidden - User is not authorized

The MCP call then returns None, and clients (e.g. Claude Code) hang retrying the web_search tool. Kiro Desktop accounts are unaffected because their auth context resolves differently, which is why this is easy to miss.

Root cause

For AWS SSO OIDC accounts the MCP web_search tool must be called on the Amazon Q endpoint, with the profile ARN supplied as a header (not in the body), and with the x-amz-json-1.0 content type:

Before (broken for SSO) After
Host https://runtime.{region}.kiro.dev/mcp https://q.{region}.amazonaws.com/mcp
profile ARN not sent header x-amzn-kiro-profile-arn
Content-Type application/json application/x-amz-json-1.0

Fix

  • For AWS_SSO_OIDC auth with a profile ARN, route web_search to https://q.{region}.amazonaws.com/mcp, send x-amzn-kiro-profile-arn, and use application/x-amz-json-1.0. Region is derived from the profile ARN.
  • Kiro Desktop auth keeps the existing q_host behavior (no change).
  • The non-200 error log now includes the response body so future MCP failures are not silent.

Tests

Adds TestMCPEndpointSelection with two cases:

  • AWS SSO OIDC -> Amazon Q host + x-amzn-kiro-profile-arn header + x-amz-json-1.0
  • Kiro Desktop -> unchanged q_host, no profile-ARN header

pytest tests/unit/test_mcp_tools.py -> 23 passed.

Verification

Verified end-to-end against a live kiro-cli (AWS SSO OIDC) account: native web_search now streams server_tool_use -> web_search_tool_result -> results, where it previously hung.

…AWS SSO OIDC

web_search via the Kiro MCP endpoint fails for kiro-cli (AWS SSO OIDC)
accounts. Requests were sent to the runtime.{region}.kiro.dev host without
a profile ARN, which the endpoint rejects with 400 'profileArn is required'
and then 403 'not authorized'. This makes clients hang while retrying.

For AWS SSO OIDC accounts, route web_search to the Amazon Q endpoint
(https://q.{region}.amazonaws.com/mcp), pass the profile ARN via the
x-amzn-kiro-profile-arn header, and use the application/x-amz-json-1.0
content type. Region is derived from the profile ARN. Kiro Desktop auth
keeps the existing q_host behavior. The error log now includes the response
body so future MCP failures are not silent.

Adds unit tests covering endpoint/header selection for both auth types.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@cla-bot

cla-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@yeeyon

yeeyon commented Jun 29, 2026

Copy link
Copy Markdown
Author

I have read the CLA and I accept its terms

@yeeyon

yeeyon commented Jun 29, 2026

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot

cla-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@cla-bot

cla-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant